local skel = fk.CreateSkill {
  name = "rmt__wenyan",
}

skel:addEffect("viewas", {
  pattern = "drugs",
  prompt = "#rmt__wenyan",
  card_filter = function (self, player, to_select, selected)
    local card = Fk:getCardById(to_select)
    return #selected == 0 and card.suit ~= Card.NoSuit and
    not table.contains(player:getTableMark("@rmt__wenyan-turn"), card:getSuitString(true))
  end,
  view_as = function (self, player, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("drugs")
    card:addSubcards(cards)
    card.skillName = skel.name
    return card
  end,
  enabled_at_play = function(self, player)
    return #player:getTableMark("@rmt__wenyan-turn") < 4
  end,
  enabled_at_response = Util.FalseFunc,
})

skel:addAcquireEffect(function (self, player, is_start)
  if not is_start then
    local room = player.room
    local suits = {}
    room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
      local use = e.data[1]
      if use.from == player.id then
        table.insertIfNeed(suits, use.card:getSuitString(true))
      end
    end, Player.HistoryTurn)
    if #suits == 0 then return end
    room:setPlayerMark(player, "@rmt__wenyan-turn", suits)
  end
end)

skel:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "@rmt__wenyan-turn", 0)
end)

skel:addEffect(fk.CardUsing, {
  refresh_events = {fk.CardUsing},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name, true) and data.card.suit ~= Card.NoSuit
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addTableMarkIfNeed(player, "@rmt__wenyan-turn", data.card:getSuitString(true))
  end,
})


Fk:loadTranslationTable{
  ["rmt__wenyan"] = "文焰",
  [":rmt__wenyan"] = "你可以将你本回合未使用过的花色的牌当【散】使用。",
  ["#rmt__wenyan"] = "文焰：将本回合未使用过的花色当【散】使用。",
  ["@rmt__wenyan-turn"] = "文焰",
  ["$rmt__wenyan1"] = "六经虽存，固圣人之糠秕！",
  ["$rmt__wenyan2"] = "弃精白、怀糟粕，文章尚不能闻，谈何天性？",
}

return skel
